package cn.zwxky.android.user.My;

import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

import cn.zwxky.android.user.Login.ForgetBean;
import cn.zwxky.android.user.R;
import cn.zwxky.android.user.Utils.LittleUtils;
import cn.zwxky.android.user.Utils.NoDoubleClickUtils;
import cn.zwxky.android.user.Utils.URLString;

/**
 * 意见反馈页面
 * Created by Administrator on 2017/3/15 0015.
 */
@ContentView(R.layout.aty_feedback)
public class FeedBackActivity extends LsfbActivity {

    /**
     * 意见输入
     */
    @ViewInject(R.id.aty_feedback_et_import)
    private EditText et_import;

    @Override
    public void initView() {
        getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        LittleUtils.setsimpletitlebar(this, "意见反馈");
    }

    @Override
    public void initEvent() {

    }


    /**
     * 点击事件
     * @param view
     */
    @OnClick({R.id.aty_feedback_btn_post})
    public void onClick(View view){
        switch (view.getId()){
            //立即提交
            case R.id.aty_feedback_btn_post:
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_import.getWindowToken(), 0);
                if (!NoDoubleClickUtils.isDoubleClick()) {
                    feedBack();
                }
                break;
        }
    }

    @Override
    public void initData() {

    }

    public void feedBack(){

        if (et_import.getText().toString().isEmpty()){
            SN.SnackShow(et_import,"请输入反馈意见再提交");
            return;
        }

        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("uid", Config.getUserId());
        hashMap.put("con", et_import.getText().toString());
        new BaseInternet().getData(URLString.FEEDBACK, hashMap, ForgetBean.class, new FeedBackEvent<ForgetBean>(), false);
    }

    @EventAnnotation
    public void FeedBackEvent(FeedBackEvent<ForgetBean> event){
        switch (event.getCode()){
            case 200:
                T.showShort(this,event.getMsg());
                finish();
                break;
            default:
                SN.SnackShow(et_import,event.getMsg());
                break;
        }
    }

}
